package com.dom;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class JDOM {

    public static void main(String[] args) {
        new JDOM().main1();
    }

    public  void main1() {
        try {
            String path = JDOM.class.getClassLoader().getResource("").toString().substring(6);
            System.out.println("path = " + path);
            SAXBuilder builder = new SAXBuilder();
            Document document = builder.build(new File(path + "demo.xml"));
            Element root = document.getRootElement();

            List<Element> children = root.getChildren();
            for (Element child : children) {
                System.out.print("车牌号码:" + child.getChild("NO").getAttributeValue("DATE"));
                System.out.print("车牌号码:" + child.getChild("NO").getText());
                System.out.println("车主地址:" + child.getChild("ADDR").getText());
            }

        } catch (JDOMException | IOException e) {
            e.printStackTrace();
        }


    }
}
